<?php


namespace App\Exception\Handler;


use App\Helpers\ApiResponse;
use Hyperf\ExceptionHandler\ExceptionHandler;
use Phper666\JwtAuth\Exception\TokenValidException;
use Psr\Http\Message\ResponseInterface;
use Throwable;


class TokenExceptionHandler extends ExceptionHandler
{
    use ApiResponse;
    public function handle(Throwable $throwable, ResponseInterface $response)
    {
        $this->stopPropagation();

        $body = '请重新登陆';

        return $this->failed($body,401);
    }

    public function isValid(Throwable $throwable): bool
    {
        return $throwable instanceof TokenValidException;
    }
}